package com.mango.community.config;

import com.mango.community.controller.interceptor.LoginRequiredInterceptor;
import com.mango.community.controller.interceptor.LoginTicketInterceptor;
import com.mango.community.controller.interceptor.MessageInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author:  MangoCookieMilk
 * @Date:     2020/7/25 15:54
 * 拦截器的配置类
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    private LoginTicketInterceptor loginTicketInterceptor;
    @Autowired
    private LoginRequiredInterceptor loginRequiredInterceptor;

    @Autowired
    private MessageInterceptor messageInterceptor;

    /**
     * @param registry
     * 配置拦截器的需要拦截的路径，不拦截那些等配置
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
            /**
             * addInterceptor 添加一个拦截器 默认是全部拦截
             * excludePathPatterns 配置那些请求不要被拦截 一般都是配置 静态资源
             * addPathPatterns 那些请求会被拦截
             */
            registry.addInterceptor(loginTicketInterceptor)
                    .excludePathPatterns("/**/*.css","/**/*.js","/**/*.png","/**/*.jpg","/**/*.jpeg");
            registry.addInterceptor(loginRequiredInterceptor)
                    .excludePathPatterns("/**/*.css","/**/*.js","/**/*.png","/**/*.jpg","/**/*.jpeg");
        registry.addInterceptor(messageInterceptor)
                .excludePathPatterns("/**/*.css","/**/*.js","/**/*.png","/**/*.jpg","/**/*.jpeg");
    }
}
